/**
 * 房间模型
 */
class Room extends CommonModels {
    tableFields() {
        return {
            "building_id": {
                "label": "楼宇ID",
                "type": "int(11)"
            },
            "region_id": {
                "label": "辖区ID",
                "type": "int(11)"
            },
            "company_id": {
                "label": "公司ID",
                "type": "int(11)"
            },
            "floor_num": {
                "label": "楼层",
                "type": "int(5)"
            },
            "name": {
                "label": "房间号",
                "type": "varchar(50)"
            },
            "area": {
                "label": "面积",
                "type": "varchar(50)"
            },
            "note": {
                "label": "备注",
                "type": "varchar(500)"
            },
        }
    }

    /**
     * 实现数据验证
     * 需要数据写入，必须在rules添加对应规则
     * 在控制中执行[模型]->attributes = $postData;
     * 否则会导致验证不生效，并且写入数据为空
     * @return [type] [description]
     */
    rules() {
        return {

        }
    }

    /**
     * 表名称
     * @returns {string}
     */
    tableName() {
        return '{{%building_room}}';
    }

    getBuilding() {
        return this.belongsTo({ name: M('Building').tableName(), as: 'building_info' }, 'building_id', 'id', ['id', 'name']);
    }

    getRegion() {
        return this.belongsTo({ name: M('Region').tableName(), as: 'region_info' }, 'region_id', 'id', ['id', 'province', 'city', 'area','street','province_name','city_name','area_name','street_name']);
    }

    getCompany() {
        return this.belongsTo({ name: M('Company').tableName(), as: 'company_info' }, 'company_id', 'id', ['id', 'name']);
    }

}

export default Room;